﻿using System.Text;
using BenchmarkDotNet.Running;
using GeneratedCode;
using Google.Protobuf;
using MemoryPack;
using MemoryPack.Compression;
using MessagePack;
using SerializeDemo;

// BenchmarkRunner.Run<Test>();
//
// Console.ReadKey();

var filePacket1 = new BasePacket<UploadPackage>
{
    Key = 1,
    Body = new UploadPackage
    {
        FileName = "人气测试.rar",
        FileLength = 100000,
        Key = CommandKey.Register,
        Body = Encoding.UTF8.GetBytes("sssss")
    }
};

var filePacketBody = MemoryPackSerializer.Serialize(filePacket1);

var resultFilePacket = MemoryPackSerializer.Deserialize<BasePacket<UploadPackage>>(filePacketBody);



LoginPackage loginPackage = new()
{
    Key = CommandKey.Login,
    Username = "asdas",
    Password = "ssss",
};

var body99 = MemoryPackSerializer.Serialize(loginPackage);

var loginPackage1 = MemoryPackSerializer.Deserialize<LoginPackage>(body99);

var stream0 = new MemoryStream();

ProtoBuf.Serializer.Serialize(stream0, loginPackage);

var body0 = stream0.ToArray();

stream0 = new MemoryStream(body0);

loginPackage = ProtoBuf.Serializer.Deserialize<LoginPackage>(stream0);


var orderRequest = new AddOrderRequest
{
    Identifier = 1,
};
var body1 = orderRequest.ToByteArray();

var request = new UserRegisterRequest
{
    Username = "wujun",
    Password = "wujun520.",
    QQ = 20424666,
    Email = "20424666@qq.com",
    Content =
        "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss",
};

var packet = new BasePacket<UserRegisterRequest>()
{
    Key = 1,
    Body = new UserRegisterRequest
    {
        Username = "wujun",
        Password = "wujun520.",
        QQ = 20424666,
        Email = "20424666@qq.com",
        Content =
            "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss",
    },
};

var body3 = MemoryPackBrotli(packet);

var packet1 = global::MemoryPack.MemoryPackSerializer.Deserialize<BasePacket<UserRegisterRequest>>(body3);


var body2 = request.Encode();


var body = MemoryPackBrotli<UserRegisterRequest>(request);

var stream = new MemoryStream();

ProtoBuf.Serializer.Serialize(stream, request);

var body5 = stream.ToArray();

byte[] MemoryPackBrotli<T>(T origin)
{
    using var compressor = new BrotliCompressor();
    global::MemoryPack.MemoryPackSerializer.Serialize(compressor, origin);
    return compressor.ToArray();
}

Console.WriteLine($"MemoryPack 序列化包：{body.Length} ProtoBufNet 序列化包：{body1.Length}");

Console.ReadKey();